﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cofe.Core;
using Cofe.Core.Implements;
using Cofe.Core.Interfaces;
using Cofe.Core.Service;
using Cofe.Data.Filter;
using Cofe.Data.Implements;

namespace Cofe.Data
{
    public class RegisterModule : RegisterModuleBase
    {
        private bool _newDatabase;
        private CacheUpdateOptions _updateOptions;

        public override void PreRegister()
        {
            base.PreRegister();
            Database.SetInitializer(new CofeDbContext.Initializer(_newDatabase));
        }

        public override void PostRegister()
        {
            base.PostRegister();
            CofeServices.CofeSettings.CacheUpdateOptions = _updateOptions;
            if (_updateOptions == CacheUpdateOptions.Active)
                CofeDBServices.ActiveDatabaseUpdater.StartActiveUpdate();
        }

        public RegisterModule(bool newDatabase = false, CacheUpdateOptions updateOptions = CacheUpdateOptions.Passive)
        {
            _newDatabase = newDatabase;
            _updateOptions = updateOptions;

            //Add all services here.
            base.registerServices(
                new EFHashTagConfig(),
                new EFDatabaseEntryConfig(),
                new EFCofeSystemInfoConfig(),
                new EFPropertyPairConfig(),
                new EFCofeSystemEventConfig(),
                new EFVolumeInfoConfig(),

                //new DatabasePropertyCache.Factory(),

                new CofeDBEventListener.Factory(),
                new DatabasePropertyDefinitions(),
                new UserFeedbackPropertyDefinitions(),
                new UserFeedbackPropertiesExpressionDefinitions(),
                new RepositoryPropertyProvider.Factory(),
                new RepositoryActionProvider.Factory(),
                new RepositoryListActionProvider.Factory(),
                new RepositorySearchActionProvider.Factory(),
                new UserFeedbackPropertyProvider.Factory(),
                new DBEntryLinkContainerBehavior.SecondaryPPFactory(),
                new DBEntryLinkContainerBehavior.PrimaryPPRegenerator(),
                //new DatabasePathParser(),
                new DBEntryListRegistrar(),
                //new EntryListPrimaryPPRegenerator(),

                new DBVolumeRegistrarGetRootBehavior(),
                new DBVolumeChangedBehavior(),
                new ParseAndUpdateDatabase(),
                new EFDatabaseUpdater(),
                new EFRepository.Factory(),
                new EntryFilterExpressionFactory(),
                new DataFilterFactory(),
                new TagsEntryFilterExpression(),
                new ParentGuidEntryFilterExpression(),
                new GuidEntryFilterExpression(),
                new FileNameEntryFilterExpression(),
                new ParseNameEntryFilterExpression(),
                new RootEntryFilterExpression(),
                new FileTypeEntryFilterExpression(),
                new OrEntryFilterExpression(),
                new PropertyEntryFilterExpression()
                );

        }

    }
}
